<template>
  <div>
    <el-header>
      <div class="left">
        <el-icon @click="handleCollapsed">
          <Menu></Menu>
        </el-icon>
        <span class="title">企业门户网站管理系统</span>
      </div>
      <div class="right">
        <span>欢迎 {{ $store.state.userInfo.username || admin }} 回来</span>
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            <el-icon>
              <User />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="handleCenter">个人中心</el-dropdown-item>
              <el-dropdown-item @click="handleLogout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
  </div>
</template>
<script setup>
import { Menu, User } from '@element-plus/icons-vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import axios from 'axios'
const store = useStore()
const handleCollapsed = () => {
  store.commit('changeCollapsed')
}

const router = useRouter()
const handleCenter = () => {
  router.push('/center')
}

const handleLogout = () => {
  localStorage.removeItem('token')
  store.commit('cleanUserInfo')
  router.push('/login')
}

</script>

<style scoped lang="scss">
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 60px;
  line-height: 60px;
  background: #409eff;
  color: #fff;
  user-select: none;

  .el-icon {
    vertical-align: middle;
    margin-right: 20px;
    cursor: pointer;
  }

  .el-dropdown {
    vertical-align: middle;
    font-weight: 700;

    .el-icon {
      font-size: 18px;
      font-weight: 700;
      color: #fff;
      margin-left: 20px;
    }
  }

}
</style>